package com.lechi.web.util;

import cn.hutool.json.JSONUtil;
import com.lechi.web.common.utils.bean.BeanUtils;
import com.lechi.web.system.domain.IotDeviceBo;
import com.lechi.web.system.domain.IotWeatherDeviceBo;

import java.util.function.Function;

public class FunctionUtil {

    public static Function<IotWeatherDeviceBo, IotWeatherDeviceBo> weather2017 = weatherDeviceBo -> {
        IotWeatherDeviceBo weatherDevice = JSONUtil.toBean(weatherDeviceBo.getContent(), IotWeatherDeviceBo.class);
        weatherDevice.setDeviceId(weatherDeviceBo.getDeviceId());
        weatherDevice.setDeviceStation(weatherDeviceBo.getDeviceStation());
        weatherDevice.setInstrumentId(weatherDeviceBo.getInstrumentId());
        weatherDevice.setIsRecordLog(weatherDeviceBo.getIsRecordLog());
        weatherDevice.setRecordLogTime(weatherDeviceBo.getRecordLogTime());
        return weatherDevice;
    };

    public static Function<IotWeatherDeviceBo, IotWeatherDeviceBo> weather2024 = weatherDeviceBo -> {
        IotWeatherDeviceBo weatherDevice = JSONUtil.toBean(weatherDeviceBo.getContent(), IotWeatherDeviceBo.class);
        weatherDevice.setDeviceId(weatherDeviceBo.getDeviceId());
        weatherDevice.setDeviceStation(weatherDeviceBo.getDeviceStation());
        weatherDevice.setInstrumentId(weatherDeviceBo.getInstrumentId());
        weatherDevice.setIsRecordLog(weatherDeviceBo.getIsRecordLog());
        weatherDevice.setRecordLogTime(weatherDeviceBo.getRecordLogTime());
        return weatherDevice;
    };

    public static Function<IotDeviceBo, IotWeatherDeviceBo> modbusRtu = iotDeviceBo -> {
        IotWeatherDeviceBo weatherDevice = new IotWeatherDeviceBo();
        BeanUtils.copyProperties(iotDeviceBo, weatherDevice);
        weatherDevice.setDeviceId(iotDeviceBo.getId());
        return weatherDevice;
    };
}
